CKEDITOR.plugins.add( 'fomatContentAll_zhongzhh',
{
	init : function( editor )
	{
		// Add the link and unlink buttons.
		editor.addCommand( 'fomatContentAll',{
    exec : function( editor )
    {
			var content =editor.getData();
			var fContent = '';
			fContent = formatContent(content);
			editor.setData(fContent);
		}
		});
		editor.ui.addButton( 'fomat',
			{
				//label : editor.lang.link.toolbar,
				label : "一键排版",
				icon: 'images/format.jpg',
				command : 'fomatContentAll'
			});		
	},
	requires : [ 'fakeobjects' ]
} );

function formatContent(arg0){
	var s= arg0;
	if(s=='')
		return '';
	s= s.replace(/<a.*?>/gi,"");
	s= s.replace(/<\/a.*?>/gi,"");
	//s= s.replace(/<strong.*?>/gi,"");
	//s= s.replace(/<\/strong.*?>/gi,"");
	s= s.replace(/<center.*?>/gi,"");
	s= s.replace(/<\/center.*?>/gi,"");
	s= s.replace(/<div.*?>/gi,"<p>");
	s= s.replace(/<\/div.*?>/gi,"</p>");
	s= s.replace(/<span.*?>/gi,"");
	s= s.replace(/<\/span.*?>/gi,"");
	s= s.replace(/<h.*?>/gi,"");
	s= s.replace(/<\/h.*?>/gi,"");
	s= s.replace(/<br.*?>/gi,"</p><p>");
	s= s.replace(/<b.*?>/gi,"");
	s= s.replace(/<\/b.*?>/gi,"");
	//s= s.replace(/\&.*?;/gi,"");
	s= s.replace(/\&nbsp;/gi,"");
	s= s.replace(/<p.*?>/gi,"<p>");
	s= s.replace(/<strong.*?>/gi,"<strong>");
	
	//console.log(s);
	//alert(s);
	
	var reg = /<img[^>]+>/g;
	var result =  s.match(reg);
	var reTmp;
	var imgTmp;
	if(result!==null){
	for(var i=0; i< result.length; i++){
		reg= /src=.*?\s/gi;
		reTmp= reg.exec(result[i]);
		imgTmp="";
		var styleJud=0;
		if(reTmp!= null)imgTmp= "<img "+reTmp[0];
		reg= /alt=\".*?\"/gi;
		reTmp= reg.exec(result[i]);
		if(reTmp!= null)
		{
			imgTmp= imgTmp+reTmp[0];
		}
		reg= /[\" ]height=\".*?\"/gi;
		reTmp= reg.exec(result[i]);
		if(reTmp!= null)
		{
			imgTmp= imgTmp+reTmp[0];
		}
		else{
			reg= /[\" ]height:.*?[;\"]/gi;
			reTmp= reg.exec(result[i]);
			if(reTmp!= null)
			{
				imgTmp= imgTmp+" style=\""+ reTmp[0].replace(/[;\"]/gi,"");
				imgTmp= imgTmp+";";
				styleJud=1;
			}
		}
		reg= /[\" ]width=\".*?\"/gi;
		reTmp= reg.exec(result[i]);
		if(reTmp!= null)
		{
			if(styleJud){imgTmp= imgTmp+"\" "+ reTmp[0];styleJud=0;}
			else{imgTmp= imgTmp+reTmp[0];}
		}
		else{
			reg= /[\" ]width:.*?[;\"]/gi;
			reTmp= reg.exec(result[i]);
			if(reTmp!= null)
			{
				if(styleJud){imgTmp= imgTmp+" "+ reTmp[0].replace(/[;\"]/gi,"");
					imgTmp= imgTmp+";";}
				else{imgTmp= imgTmp+ " style=\""+reTmp[0].replace(/[;\"]/gi,"");
					imgTmp= imgTmp+";";
					styleJud=1;}
			}
		}
		if(styleJud)imgTmp= imgTmp+"\"";
		if(imgTmp!="")imgTmp= imgTmp+" />";
		s= s.replace(result[i],imgTmp);
	}}
	
	reg = /<p>[\s　]*<\/p>/gi;
	result =  s.match(reg);
	if(result!==null){
	for(var i=0; i< result.length; i++){
		s= s.replace(result[i],"");
	}}
	
	reg = /<p>[\s　]*<[^s]/gi;
	result =  s.match(reg);
	if(result!==null){
	for(var i=0; i< result.length; i++){
		s= s.replace(result[i].substring(0,result[i].length-1),"<");
	}}
	reg = /[^n][^g]>[\s　]*<\/p>/g;
	result =  s.match(reg);
	if(result!==null){
	for(var i=0; i< result.length; i++){
		s= s.replace(result[i].substring(2,result[i].length),">");
	}}
	
	reg = /<img[^>]+>/g;
	result =  s.match(reg);
	if(result!==null){
	for(var i=0; i< result.length; i++){
		imgTmp= '<p style="text-align: center;">'+ result[i] + "</p>";
		s= s.replace(result[i],imgTmp);
	}}
	
	
	s= s.replace(/<p>[\s　]*/gi,"<p>　　");
	s= s.replace(/<strong>[\s　]*/gi,"<strong>　　");
	s= s.replace(/<p>[\s　]*<strong/gi,"<p><strong");
	
	return s;
}